<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 在排序数组中查找元素的第一个位置和最后一个位置 -->
    <script>
      var searchRange = function (nums, target) {
        var targete = [-1, -1]
        for (let i = nums.length - 1; i >= 0; i--) {
          if (nums[i] == target) {
            targete[0] = i
          }
        }
        if (targete[0] == -1) {
          return targete
        }
        for (let j = 0; j < nums.length; j++) {
          if (nums[j] == target) {
            targete[1] = j
          }
        }
        return targete
      }
      console.log(searchRange([5, 7, 7, 8, 8, 10], 8))
    </script>
  </body>
</html>
